//
//  LXPrefix.swift
//  LXTXShop
//
//  Created by apple on 2018/4/3.
//  Copyright © 2018年 LX. All rights reserved.
//

import UIKit

// MARK: - init config
let app = UIApplication.shared.delegate as! AppDelegate
let ENCRYPTIONKEY = "=TY3&^biq8()^mACUGP8Q35="
let BASEREQUESTURL = ""
let TABLECELLCOLOR = RGB(200, 199, 204)
let HOMENAVCOLOR = RGB(110,100,199)
let VERSION = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
let home = NSHomeDirectory() as NSString;
/// 2、获得Documents路径，使用NSString对象的stringByAppendingPathComponent()方法拼接路径
let docPath = home.appendingPathComponent("Documents") as NSString;
/// 3、获取文本文件路径
let AccountPath = docPath.appendingPathComponent("u.archive")
let AutoLoign = "autoLoign" //自动登录标志
let AuthCodeDuration = 60

let LoginSuccessNotification = "LoginSuccess"

let kAdaptiveValue = (app.scWidth/320.0) // 适配
let kPlaceholderDefault:UIImage = UIImage(named:"fxz_no_pic")!

func RGBA (_ r:CGFloat, _ g:CGFloat, _ b:CGFloat,_ a:CGFloat) -> UIColor {
    return UIColor (red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a)
}

func RGB (_ r:CGFloat, _ g:CGFloat, _ b:CGFloat) -> UIColor {
    return UIColor (red: r/255.0, green: g/255.0, blue: b/255.0, alpha: 1)
}

func RANDCOLOR () -> UIColor {
    return RGB(CGFloat(arc4random_uniform(255)), CGFloat(arc4random_uniform(255)), CGFloat(arc4random_uniform(255)))
}

func FONT(_ size:CGFloat) -> UIFont {
    return UIFont(name: "Helvetica", size: size)!
}

func FONTBOLD(_ size:CGFloat) -> UIFont {
    return UIFont(name: "Helvetica-Bold", size: size)!
}


func labelWidth(_ labelStr:String,font:UIFont,height:CGFloat) -> CGFloat {
//    let statusLabelText: NSString = labelStr as NSString
//    let size = CGSize(width: 900, height: height)
//    let dic = NSDictionary(object: font, forKey: NSFontAttributeName as NSCopying)
//    let strSize = statusLabelText.boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: dic as? [String : AnyObject], context: nil).size
//    return strSize.width
    return 0
}

func addDict <KeyType, ValueType> (_ left: inout Dictionary<KeyType, ValueType>, right: Dictionary<KeyType, ValueType>) {
    for (k, v) in right {
        left.updateValue(v, forKey: k)
    }
}

func colorWithHexString(_ hex:String) -> UIColor {
    
    var h = String()
    if hex.hasPrefix("#"){
        h = ((hex as NSString).substring(from: 1) as NSString) as String
    }
    let redStr = (h as NSString ).substring(to: 2)
    let greenStr = ((h as NSString).substring(from: 2) as NSString).substring(to: 2)
    let blueStr = ((h as NSString).substring(from: 4) as NSString).substring(to: 2)
    var r:CUnsignedInt = 0, g:CUnsignedInt = 0, b:CUnsignedInt = 0;
    Scanner(string:redStr).scanHexInt32(&r)
    Scanner(string: greenStr).scanHexInt32(&g)
    Scanner(string: blueStr).scanHexInt32(&b)
    return UIColor(red: CGFloat(r)/255.0, green: CGFloat(g)/255.0, blue: CGFloat(b)/255.0, alpha: 1)
    
}

// MARK: - debuy log

func XLog<T>(_ message: T)
{
    #if DEBUG
        print("\(message)")
    #endif
}

// MARK: - message











